#include <iostream>

using namespace std;

const int V = 2e4+10;
const int N = 40;
int dp[N][V];
int v,n;
int a[N];
//dp[i][j] : 第i个物品,j个体积
//dp[i][j] = dp[i-1][j]
//dp[i][j] = dp[i-1][j-a[i]] + a[i]

int main()
{
    cin >> v >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= n;i++)
    {
        for(int j = 0;j<=v;j++)
        {
            dp[i][j] = dp[i-1][j];
            if(j>=a[i])
            {
                dp[i][j] = max(dp[i][j],dp[i-1][j-a[i]]+a[i]);
            }
        }
    }
    cout << v - dp[n][v] << endl;


    return 0;
}